package com.mikasa.springboot.dubbo.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.mikasa.springboot.dubbo.api.IDubboDemoService;
import com.mikasa.springboot.dubbo.model.Comic;
import com.mikasa.springboot.dubbo.model.ComicResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 *
 * @author User
 * @date 17/1/18
 */

@Service
@Component
public class DubboDemoServiceImpl implements IDubboDemoService {

    private static final Logger LOGGER = LoggerFactory.getLogger(DubboDemoServiceImpl.class);


    @Override
    public String sayHello(String name) {
        LOGGER.info("dubbo服务[sayHello]##########");
        return "hello " + name;
    }

    @Override
    public ComicResult handleComic(Comic comic) {
        ComicResult comicResult = new ComicResult();
        if(null != comic){
            comicResult.setCode(1);
            comicResult.setMessage(JSON.toJSONString(comic));
        }else {
            comicResult.setCode(0);
            comicResult.setMessage("动漫内容为空");
        }
        return comicResult;
    }
}
